/*
 * Copyright (c) 2009, Servoy-stuff
 * 
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
 * http://www.fsf.org/licensing/licenses/lgpl.txt
 */
package net.stuff.servoy.beans.slider.wicket;


import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;

/**
 * @author Servoy Stuff
 * http://www.servoy-stuff.net/
 */
public class SliderUpdatingBehavior extends AjaxFormComponentUpdatingBehavior {

	private static final long serialVersionUID = 1L;
	
	public final static String DATA_CHANGE = "onchange";
	public final static String LOST_FOCUS = "onblur";
	protected ServoyWicketSlider parent;

	/**
	 * @param event
	 * @param parent
	 */
	public SliderUpdatingBehavior(String event, ServoyWicketSlider parent) {
		super(event);
		this.parent = parent;
	}

	/* (non-Javadoc)
	 * @see org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior#onUpdate(org.apache.wicket.ajax.AjaxRequestTarget)
	 */
	@Override
	protected void onUpdate(AjaxRequestTarget target) {
		String evt = getEvent();
		if (evt.equalsIgnoreCase(DATA_CHANGE) || evt.equalsIgnoreCase(LOST_FOCUS)) {
			parent.testChanged();
			if (evt.equalsIgnoreCase(DATA_CHANGE)) {
				target.focusComponent(parent);
			}
		}
	}

}
